#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int dx[2] = { 0, 1 };
    int dy[2] = { 1, 0 };
    int ret = 0;
    bool bp[101][101];
    int wardrobeFinishing(int m, int n, int cnt) {
        dfs(m, n, cnt, 0, 0);
        return ret;
    }
    void dfs(int m, int n, int cnt, int x, int y)
    {
        bp[x][y] = true;
        int a = x, b = y, sum = 0;
        while (a) sum += a % 10, a /= 10;
        while (b) sum += b % 10, b /= 10;
        if (sum > cnt) return;

        ret++;
        for (int k = 0; k < 2; k++)
        {
            int i = x + dx[k], j = y + dy[k];
            if (i >= 0 && i < n && j >= 0 && j < m && bp[i][j] == false) dfs(m, n, cnt, i, j);
        }
    }
};